/**
 * http://usejsdoc.org/
 */
var Login = require(global.CON+'login');

/**
 * 路由转换
 * @param req
 * @param res
 * @param pathname 路径名称
 */
exports.router = function(res,req){
	var pathname = decodeURI(global.lib.url.parse(req.url).pathname);
	global.lib.httpParam.init(res,req);
	global.sessionLib = global.lib.session.start(res,req);
	var model = pathname.substring(1),
		controller = global.lib.httpParam.GET('c'),
		Class = '';
	if (pathname ===  '/favicon.ico') {//忽略/favicon.ico请求
		return;
	}else if(pathname === '/' || pathname === '/index'){//默认进入首页
		res.render(global.VIEW + 'index.jade');
		return;
	}else {
		try {
			Class = require(global.CON+model);
		} catch (e) {
			global.lib.staticModule.getStaticFile(pathname,res,req);
			return;
		}
		if(Class){
			var login = new Login(res,req);
			var ret = login.checkSession(model);
			if(ret){
				var object =  new Class(res,req);
				object[controller].call();
			}else{
				res.render(global.VIEW+'index.jade');
			}
		}else{
			res.writeHeader(404,{"Content-Type":"text/plain"});
			res.end('can not find source!');
		}
	}
};